Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt5 opengl widget givng error openglfunctions line 656
Forum Updated to NodeBB v4.3 + New Features

Qt5 opengl widget givng error openglfunctions line 656

Scheduled Pinned Locked Moved Solved General and Desktop
openglopengl es 3.0widget
5 Posts 3 Posters 1.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gtx0908
    wrote on last edited by gtx0908
    #1

    hey guys
    using windows 10 and qt creator qt 5
    im trying to out a opengl 3 widget on qt I have looked at some youtube tutorials and such but it is giving me this error when using qt5 with openglwidget using a widget on the ui

    main.cpp

    #include "mainwindow.h"
    #include <QApplication>
    #include <thread>
    #include <algorithm>
    #include <vector>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    

    glwidget.cpp

    #include "glwidget.h"
    
    glwidget::glwidget(QWidget *parent):QOpenGLWidget {parent}
    {
    
    }
    
    void glwidget::initializeGL()
    {
        glClearColor(0,0,0,1);
        initializeOpenGLFunctions();
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHTING);
        glEnable(GL_COLOR_MATERIAL);
    
    }
    
    void glwidget::paintGL()
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    
    
    
    
    }
    
    void glwidget::resizeGL(int w, int h)
    {
    
    
    
    
    
    
    }
    
    void glwidget::qColorToRGB(const QColor &C, float &r, float &g, float &b) const
    {
    
    
    
    
    
    }
    
    float glwidget::normalize_0_1(float val,float min,float max) const
    {
    
    
    
        return (val - min) / (max - min);
    }
    

    glwidget.h

    #ifndef GLWIDGET_H
    #define GLWIDGET_H
    
    #include <QGLWidget>
    #include <QOpenGLWidget>
    #include <QOpenGLFunctions>
    #include <QProcess>
    
    class glwidget : public QOpenGLWidget,public QOpenGLFunctions
    {
      //  Q_OBJECT
    public:
        explicit glwidget(QWidget *parent = nullptr);
    protected:
        void initializeGL();
        void paintGL() override;
        void resizeGL(int w,int h) override;
    private:
        void qColorToRGB(const QColor &C, float &r,float &g,float &b) const;
        float normalize_0_1(float val,float min,float max) const;
    };
    
    
    #endif // GLWIDGET_H
    

    Mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
    };
    
    #endif // MAINWINDOW_H
    
    Mainwindow.cpp 
    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    i have promoted

    screenshot of error

    qtopenglnotworking.PNG ![alt text](image url)

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #4
      void glwidget::initializeGL()
      {
          glClearColor(0,0,0,1);       // <--- HERE
          initializeOpenGLFunctions();
          ...
      

      You are using a GL function before a pointer to it was resolved. Don't call any glXXX functions before initializeOpenGLFunctions(). Just switch those two lines and you should be good to go.

      G 1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        The code in your image does not seem to match what you posted.

        It's missing the initializeOpenGLFunctions(); call in your initializeGL override.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gtx0908
          wrote on last edited by gtx0908
          #3

          ah theres a myglwidget that i tried using from a second youtube video tutorial but i went back to glwidget.h/cpp which was the original tutorial the myglwidget.h/cpp file in the image can be ignored

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #4
            void glwidget::initializeGL()
            {
                glClearColor(0,0,0,1);       // <--- HERE
                initializeOpenGLFunctions();
                ...
            

            You are using a GL function before a pointer to it was resolved. Don't call any glXXX functions before initializeOpenGLFunctions(). Just switch those two lines and you should be good to go.

            G 1 Reply Last reply
            2
            • Chris KawaC Chris Kawa
              void glwidget::initializeGL()
              {
                  glClearColor(0,0,0,1);       // <--- HERE
                  initializeOpenGLFunctions();
                  ...
              

              You are using a GL function before a pointer to it was resolved. Don't call any glXXX functions before initializeOpenGLFunctions(). Just switch those two lines and you should be good to go.

              G Offline
              G Offline
              gtx0908
              wrote on last edited by
              #5

              @Chris-Kawa ah ok that worked and learned something new thanks

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved